# -*- encoding: utf-8 -*-

'''
@File    :   logger.py
@Time    :   2023/12/16
@Author  :   AiurLake 
@Desc    :   日志采集
'''

import os, pathlib
import logging
import logging.config as log_config
from pathlib import Path

print("prepare logger start")
# 检测日志目录是否存在
projectDir = os.path.abspath(os.getcwd())
logDirPath = os.path.join(projectDir, "logs/")
try:
    logDirObj = pathlib.Path(logDirPath)
    if not (logDirObj.exists() and logDirObj.is_dir()):
        dirPath = Path(logDirPath)
        dirPath.mkdir()
except Exception as e:
     print("prepare logs/ dir exception: {}".format(e))
        
# 日志采集配置
curPath = os.path.abspath(__file__)
curDir = os.path.dirname(curPath)
logConfigPath = os.path.join(curDir, "logging.conf")
log_config.fileConfig(logConfigPath, disable_existing_loggers=False)
logger = logging.getLogger("app")
print("prepare logger end")